package com.itheima.service.db;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.itheima.domain.db.BlackList;
import com.itheima.mapper.BlackListMapper;
import com.itheima.vo.PageBeanVo;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

@DubboService
public class BlackListServiceImpl implements BlackListService {

    @Autowired
    BlackListMapper blackListMapper;

    @Override
    public PageBeanVo findByPage(Integer pageNum, Integer pageSize, Long userId) {
        //1.创建分页对象page
        Page<BlackList> page = new Page<>(pageNum, pageSize);

        //2.创建条件查询对象
        QueryWrapper<BlackList> wrapper = new QueryWrapper<>();
        wrapper.eq("user_id",userId);

        //3.调用mapper查询当前页数据 ,返回page
        page = blackListMapper.selectPage(page,wrapper);

        //4.创建PageBeanVo对象,返回
        return new PageBeanVo(pageNum,pageSize,page.getTotal(),page.getRecords());
    }

    @Override
    public void deleteByUserIdAndBlackId(Long userId, Long blackId) {
        QueryWrapper<BlackList> wrapper = new QueryWrapper<>();
        wrapper.eq("user_id",userId).eq("black_user_id",blackId);
        blackListMapper.delete(wrapper);
    }
}
